<?php
class HomeController extends AppController {
    
    public $uses = array('User');
    
    public function isAuthorized() {
        
    }
    
    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('index','loggedout');
    }
    
    public function index() {
    }
    
    public function login() {
        if ($this->request->is('post')) {
            $user = $this->User->find('first', array(
                'conditions' => array(
                    'User.username' => $this->data['User']['username'],
                    'User.password' => $this->Auth->password($this->data['User']['password']),
                    'User.status' => 'ACTIVE'
                )
            ));
            if ($user) {
                unset($user['User']['password']);
                if ($this->Auth->login($user['User'])) {
                    return $this->redirect($this->Auth->redirect());
                } else {
                    $this->Session->setFlash(__('[Usuario y/o contraseña inválida]'), 'default', array(), 'auth');
                }
            } else {
                $this->Session->setFlash(__('[Usuario y/o contraseña inválida]'), 'default', array(), 'auth');
            }
        }
    }
    
    public function logout() {
        $this->redirect($this->Auth->logout());
    }
    
    public function loggedin() {
    }
    
    public function loggedout() {
    }
}
?>